package kr.couponplay.android.domain.app;

import kr.couponplay.android.ApiUrl;
import kr.couponplay.android.AppContext;
import kr.couponplay.android.domain.BaseDao;
import kr.couponplay.android.support.HttpUtils;
import kr.couponplay.android.support.JsonUtils;

import org.json.JSONObject;

public class AppInfomationDao extends BaseDao {
	
	public AppInformation initializeApp() {
		try {
			String result = HttpUtils.executeToStr(ApiUrl.informationUrl + "?" + AppContext.getSid(getApplicationContext()), 1500);
			JSONObject jSONObject = new JSONObject(result);
			
			AppInformation appInformation = new AppInformation();
			appInformation.setAppVersion(jSONObject.getString("appVersion"));
			appInformation.setDealTotalCount(jSONObject.getInt("dealTotalCount"));
			appInformation.setDealListLimitCount(jSONObject.getInt("dealListLimitCount"));
			appInformation.setLastUpdatedTime(jSONObject.getLong("lastUpdatedTime"));
			appInformation.setEventName(JsonUtils.getStringValue(jSONObject, "eventName"));
			appInformation.setCategoryJson(jSONObject.getJSONArray("categories").toString());
			appInformation.setProviderJson(jSONObject.getJSONArray("providers").toString());
			appInformation.setAdPlatformType(jSONObject.getString("adPlatformType"));
			appInformation.setUseAdPlatform(jSONObject.getBoolean("useAdPlatform"));
			return appInformation;
		} catch (Exception e) {
			throw new IllegalStateException(e.getMessage(), e);
		}
	}
}
